import pytest
import logging
from src.common.utils import Driver, Tools
from src.pages.base_page import BasePage


@pytest.fixture(scope='class')
def init_browser(request):
    """
    启动浏览器并最大化窗口
    Args:
        request: Pytest的内置函数
    """
    request.cls.driver = Driver.browser()
    request.cls.driver.maximize_window()
    request.cls.driver.implicitly_wait(25)

    def teardown():
        logging.info('+--------------------------+')
        logging.info('|        测试执行结束        |')
        logging.info('+--------------------------+')
        request.cls.driver.quit()
        # logging.info('正在发送测试结果邮件......')
        # Tools.send_mail('test@123.com', 'test@234.com', 'RMBKXURUBTSEKZYT', file='D:\\tmp\\report.html')
    request.addfinalizer(teardown)


@pytest.fixture(scope='class')
def user_login(request):
    """
    用户登录进入首页
    Args:
        request: Pytest的内置函数
    """
    request.cls.driver.get('https://tsplus.zhibocloud.cn/auth/login')
    BasePage(request.cls.driver).login('deja_vu', '123456')
    logging.info('+--------------------------+')
    logging.info('|        测试执行开始        |')
    logging.info('+--------------------------+')
